<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="任务名称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="taskId" hidePagination>
				<el-table-column label="任务名称" prop="text" width="400" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="开始时间" prop="startDate" width="100"></el-table-column>
				<el-table-column label="工期" prop="duration" width="100">
					<template #default="scope">
						{{scope.row.duration}}/天
					</template>
				</el-table-column>
				<el-table-column label="责任人" prop="userName" width="100"></el-table-column>
				<el-table-column label="当前进度" prop="progress" width="150">
					<template #default="scope">
						{{Number(scope.row.progress)*100}}%
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="170">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">指派</el-button>
						</el-button-group>
					</template>
				</el-table-column>

			</scTable>
		</el-main>
	</el-container>
	<select-user-dialog v-model:accountId="form.accountId" ref="selectUserDialog" :is-not-show-btn="true" :mode="false" @success="updateTaskList"/>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	name: 'Project Task Allocation',
	components: {scSelectFilter,selectUserDialog},
	data() {
		return {
			form:{
				taskId:'',
				accountId:''
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "明日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月后",
							value: "5"
						}
					]
				},
				{
					title: "项目等级",
					key: "proLevel",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "项目类型",
					key: "proSort",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
			],
			apiObj: this.$API.project.proTask.getTaskAllocationList,
			selection: [],
			search: {
				date:'',
				proLevel:'',
				proSort:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSysDicByCode()
	},
	methods: {
		async getSysDicByCode()
		{
			var res = await this.$API.project.proDic.getProDicByCode.get({code:'proLevel'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
			res = await this.$API.project.proSort.getProSort.get();
			if (res.code == 200) {
				this.filterData[2].options=this.filterData[2].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async filterChange(data){
			this.search.date=data.date
			this.search.proLevel=data.proLevel
			this.search.proSort=data.proSort
			this.$refs.table.upData(this.search)
		},
		//编辑
		table_edit(row){
			this.form.taskId = row.taskId;
			this.$nextTick(() => {
				this.$refs.selectUserDialog.selectOrgUser();
			})
		},
		async updateTaskList(){
			let res = await this.$API.project.proTask.updateProTask.post(this.form);
			if (res.code == 200) {
				this.$message.success("操作成功")
				this.$refs.table.refresh()
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch(){
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style>
</style>
